package com.yamibuy.ec.resource.domain;


/**
 * 错误信息码定义
 *
 * @author: 625
 * @version: 2020年06月12日 13:59
 */
public interface Coder {

	/**
	 * 获取code
	 *
	 * @return
	 */
	int getCode();

	/**
	 * 获取错误描述信息
	 *
	 * @return
	 */
	String getMsg();


	/**
	 * 参数构建
	 *
	 * @param params
	 * @return
	 */
	default Coder build(String... params) {
		int code = getCode();
		String msg = String.format(getMsg(), params);
		Coder coder = new Coder() {
			@Override
			public int getCode() {
				return code;
			}

			@Override
			public String getMsg() {
				return msg;
			}
		};
		return coder;
	}

	/**
	 * 系统错误码
	 */
	enum System implements Coder {

		SUCCESS(200, "操作成功"),


		NOT_FOUND_IMG(404, "资源不存在"),

		ERROR(500, "未知错误"),

		Amazon_S3_Exception(501, "AWS未知异常"),

		PATH_UNKONW(502, "PATH未识别"),
		;

		/**
		 * 错误码
		 */
		private int code;

		/**
		 * 错误信息
		 */
		private String msg;

		System(int code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		@Override
		public int getCode() {
			return code;
		}

		@Override
		public String getMsg() {
			return msg;
		}
	}
}
